/**
 * Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.txzt.gaea.common.exception;

import com.txzt.base.core.RtnInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * 全局的的异常拦截器（拦截所有的控制器）（带有@RequestMapping注解的方法上都会拦截）
 *
 * @author fengshuonan
 * @date 2016年11月12日 下午3:19:56
 */
@ControllerAdvice
@Order(2)
@Slf4j
public class GlobalExceptionHandler {


    /**
     * 拦截业务异常
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public RtnInfo bussiness(Exception e) {
        log.error("业务异常:", e);
        return RtnInfo.SERVER_ERROR;
    }

    /**
     * 处理自定义异常
     */
    @ExceptionHandler(CustomException.class)
    public RtnInfo<?> handleRRException(CustomException e){
        log.error(e.getMessage(), e);
        return RtnInfo.error(RtnInfo.SERVER_ERROR.getCode(),e.getMessage());
    }


}
